package com.student_exam_system.dao;

import com.student_exam_system.pojo.Paper;
import com.student_exam_system.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
    /**添加一个User
     * @param user 传入user类
     * @return int
     */
    int addUser(User user);
    /**根据id删除一个User
     * @param id 传入id
     * @return int
     */
    int deleteUserById(int id);

    /**更新User
     * @param user 传入user类
     * @return int
     */
    int updateUser(User user);
    /**根据id查询,返回一个User
     * @param id 传入id
     * @return int
     */
    User queryUserById(int id);

    /**根据id查询,返回一个User
     * @param phoneNum 传入电话号码
     * @return int
     */
    User queryUserByUsername(@Param("userPhoneNum") String phoneNum);

    /**根据id查询,返回一个User
     * @param phoneNum 传入电话号码
     * @param pwd 密码
     * @return int
     */
    User queryUserByPhoneAndPwd(@Param("userPhoneNum") String phoneNum, @Param("userPassword") String pwd);
    /**查询全部User,返回list集合
     * @return List<User>
     */
    List<User> queryAllUser();

    /**
     * 查询用户【主要用于登录】
     * @param userPhoneNum  用户手机号/账号
     * @param userPassword  用户密码
     * @return  user对象
     */
    @Select("select *from user where user_identity = 2 and user_phoneNum= #{userPhoneNum} and user_password = #{userPassword} " )
    @Results({
            @Result(column = "user_id", property = "userId"),
            @Result(column = "user_phoneNum", property = "userPhoneNum"),
            @Result(column = "user_password",property = "userPassword"),
            @Result(column = "user_identity" ,property = "userIdentity"),
            @Result(column = "user_class",property = "userClass")
    }
    )
    User selectUser(@Param("userPhoneNum")String userPhoneNum, @Param("userPassword")String userPassword);

    /**
     * 注册教师账号
     * @param userPhoneNum 教师手机号
     * @param userPassword  密码
     * @param userClass 选择班级
     * @return user对象
     */
    @Insert("insert into user values (null,#{userPhoneNum},#{userPassword},'2',#{userClass})")
    User insertUser(@Param("userPhoneNum")String userPhoneNum,@Param("userPassword")String userPassword,@Param("userClass")int userClass);

    /**
     * 获得班级的id
     * @param className  班级名称
     * @return  int班级id
     */
    @Select("select class_id from exam.class where class_name = #{className}")
    int getClassId(String className);

    /**
     * 教师出卷【手动/自动（random）出卷：首先先创建了试卷，然后在多次执行试题与试卷的插入】
     * @param paper paper对象
     * @return  paper对象
     */
    @Insert("insert into exam.paper values (0,#{paper.getPaperTeacher()},#{paper.getPaperDateTime},#{paper.getPaperName})")
    Paper insertPaper(Paper paper);

    /**
     * 试卷与试题之间的关系
     * @param questionId  试题id
     * @param paperId 试卷id
     * @return  int 是否插入插入成功
     */
    @Insert("insert into exam.paper_question values (null,0,#{questionId},#{paperId})")
    int insertPq(@Param("questionId")int questionId,@Param("paperId")int paperId);





}
